﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using TemplateTest;

namespace EasyTemplates.Test
{
    [TestFixture]
    public class Template_Test
    {
        [Test]
        public void Constant()
        {
            TestTemplate(
                template => {},
                TestData.Simple,
                TestData.Simple_Result
            );
        }

        [Test]
        public void Code()
        {
            TestTemplate(
                template => { template.Parameters.Add("P1", new Parameter(5) ); },
                TestData.CodeReplacement,
                TestData.CodeReplacement_Result
            );
        }

        [Test]
        public void VisualBasic()
        {
            TestTemplate(
                template => 
                { 
                    template.Parameters.Add("P1", new Parameter(5));
                    template.Language = TemplateLanguages.VisualBasic;
                },
                TestData.CodeReplacement,
                TestData.CodeReplacement_Result
            );
        }

        [Test]
        public void NullValue()
        {
            TestTemplate(
                template => { template.Parameters.Add("P1", new Parameter(null)); },
                TestData.NullValue,
                TestData.NullValue_Result
            );
        }

        [Test]
        public void Value()
        {
            TestTemplate(
                template => 
                {
                    template.Parameters.Add(
                        "P1",
                        new Parameter("Value of P1")
                    );
                    template.Parameters.Add(
                        "P2",
                        new Parameter("Value of P2")
                    );
                },
                TestData.ValueReplacement,
                TestData.ValueReplacement_Result
            );
        }

        [Test]
        public void PublicInterface()
        {
            Template template = new Template(
                    TestData.ValueReplacement,
                    "P1", "Value of P1",
                    "P2", "Value of P2"
                );
            Assert.AreEqual(TestData.ValueReplacement_Result, template.Generate());
        }

        public void TestTemplate(Action<Template> configure, string templateBody, string expected)
        {
            Template template = new Template();
            template.TemplateBody = templateBody;
            configure(template);
            Assert.AreEqual(expected, template.Generate());            
        }
    }
}
